package com.dmall.ssm.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import com.dmall.ssm.param.QueryCriterion;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.dmall.ssm.pojo.User;

public interface UserDao {

	@Select("<script>" +
			"select * from dmall_user" +
			"<where>" +
			"<if test='params.eqField != null'>" +
			"<foreach collection='params.eqField' index='col' item='val'>" +
			"<if test='val != null and val != \"\"'>" +
			"<![CDATA[ and #{col} = #{val} ]]>" +
			"</if>" +
			"</foreach>" +
			"</if>" +
			"<if test='params.inField != null'>" +
			"<foreach collection='params.inField' index='col' item='valList'>" +
			"<![CDATA[ and #{col} in ]]>" +
			"<foreach collection='valList' item='val' separator=',' open='(' close=')'>" +
			"<if test='val != null and val != \"\"'>" +
			"#{val}" +
			"</if>" +
			"</foreach>" +
			"</foreach>" +
			"</if>" +
			"</where>" +
			"</script>")
	List<User> findByCriterion(@Param("params") QueryCriterion params);

	@Select("select * from dmall_user where id = #{id}")
	User findById(Integer id);
	
	@Select("select * from dmall_user")
	List<User> findAll();
	
	@Update("update dmall_user set real_name = #{realName} where id = #{id}")
	int updateRealName(User user);

	@Select("<script>"
			+ "select * from dmall_user"
			+ "<where>"
			+ "<if test='contains != null and contains != \"\" and contains != 5'>"
			+ "and id = #{id}"
			+ "</if>"
			+ "</where>"
			+ "</script>")
	List<User> findByContains(@Param("id") Integer id, @Param("contains") Integer contains);

	@Select("<script>" +
			"select * from dmall_user" +
			"<if test='id != null and id != \"\" and id != 5'>" +
			"where id = #{id}" +
			"</if>" +
			"</script>")
	List<User> notContains(@Param("id") Integer id);
}
